home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / smail-3.1.28 / src / mkdrivtab.sh < prev    next >
Encoding:
Text File  |  1992-09-05  |  6.3 KB  |  239 lines

  1. # @(#)src/mkdrivtab.sh    1.8 9/6/92 04:40:16
  2.  
  3. # Script to create drivertab.c and the driver makefile directories
  4. # from a driver configuration file.  This script makes heavy use of
  5. # the awk script mkdriv.awk to actually process the contents of the
  6. # configuration file.  The awk script produces output tokens which
  7. # tell this script how to operate.
  8. #
  9. # The format of a driver file is a collection of one line records
  10. # describing the drivers which are to be linked to the smail binary.
  11. # Additional source and header files can be specified for use in a
  12. # particular library file using the special driver name "library".
  13. #
  14. # Drivers come in four types:  director, router, transport and lookup
  15. # drivers.  A line describing a driver is of the following form:
  16. #
  17. #    type name [modifiers ...]
  18. #
  19. # where type is one of "director", "router", "transport" or "lookup",
  20. # and where name is the symbolic name for the driver, for reference
  21. # from run-time configuration files.
  22. #
  23. # There can be modifiers applied to an entry.  These modifiers can be
  24. # one of the following:
  25. #
  26. #    source=name.c    This modifier declares that the source for the
  27. #            driver is in the file "name.c" in the source
  28. #            directory for the specific driver type.  The
  29. #            default source file name is the symbolic name
  30. #            of the driver with a suffix of ".c".
  31. #
  32. #    header=name    This modifier declares that the header file
  33. #            associated with the driver is in the file
  34. #            "name" in the source directory for the
  35. #            specified driver type.  By default lookup
  36. #            drivers do not have header files, while
  37. #            director, router and transport drivers have
  38. #            header files with the basename of the source
  39. #            file and a suffix of ".h".
  40. #
  41. #    nocache        This modifier declares that the driver does
  42. #            not have a "cache" entry point.  This does not
  43. #            apply to lookup drivers.
  44. #
  45. #    nofinish    This modifier declares that the driver does
  46. #            not have a "finish" entry point.  This does
  47. #            not apply to lookup drivers.
  48. #
  49. #    nobuilder    This modifier declares that the driver does
  50. #            not have a "builder" entry point.  This does
  51. #            not apply to lookup drivers.
  52. #
  53. # Additional source and header files for a particular driver library
  54. # can be specified using a line of the form:
  55. #
  56. #    type library [name.c | name.h] ...
  57. #
  58. # where type specifies the driver library, library is the keyword
  59. # "library", and where name.c specifies a source file in the driver
  60. # source directory, and where name.h specifies a header file in the
  61. # driver source directory.
  62. #
  63. # Blanks lines are okay, and comments can be started with a '#'
  64. # character and continue until the end of the line.
  65. #
  66. # The following is a simple example of a driver file:
  67. #
  68. #    # director drivers
  69. #    director  aliasfile
  70. #    director  forwardfile nocache nofinish source=fwdfile.c
  71. #    director  user          nocache nofinish
  72. #    director  library     dtlib.c dtlib.h
  73. #
  74. #    # router drivers
  75. #    router    pathalias
  76. #    router      uuname      # the command output may be cached
  77. #    router      smarthost   nocache nofinish
  78. #    router      library     rtlib.c rtlib.h
  79. #
  80. #    # transport drivers
  81. #    transport pipe          nocache nofinish
  82. #    transport appendfile  nocache nofinish
  83. #    transport library     tplib.c tplib.h
  84. #    transport library     bsmtp.c bsmtp.h
  85.  
  86. if [ $# -gt 0 ]; then
  87.     driver_file=$1
  88.     exec < $driver_file
  89. else
  90.     driver_file="<standard-input>"
  91. fi
  92.  
  93. sed -e 's/#.*//' -e '/^[     ]*$/d' |
  94.     if [ -f mkdriv.perl ]; then
  95.     perl mkdriv.perl
  96.     else
  97.     awk -f mkdriv.awk
  98.     fi |
  99.     sed    -e '/%.*%NULL/d'            \
  100.     -e 's/%CC%/extern void /'        \
  101.     -e 's/%DD%/extern struct addr */'    \
  102.     -e 's/%RD%/extern void /'        \
  103.     -e 's/%TD%/extern void /'        \
  104.     -e 's/%VV%/extern void /'        \
  105.     -e 's/%FF%/extern void /'        \
  106.     -e 's/%BB%/extern char */'        \
  107.     -e 's/%LO%/extern int /'        \
  108.     -e 's/%LC%/extern void /'        \
  109.     -e 's/%LL%/extern int /' |
  110.     (
  111.     if [ -f drivertab.c ]; then
  112.         echo "Build drivertab.c, backup in .drivertab.c" 1>&2
  113.         mv drivertab.c .drivertab.c
  114.     else
  115.         echo "Build drivertab.c ..." 1>&2
  116.     fi
  117.     outfile=drivertab.c
  118.     cat <<EOF > $outfile
  119. /*
  120.  * drivertab.c:
  121.  *    define the available director, router, transport and lookup
  122.  *    drivers for use by smail.
  123.  *
  124.  * THIS FILE IS GENERATED AUTOMATICALLY BY THE SCRIPT $0 FROM
  125.  * THE DRIVER CONFIGURATION FILE $driver_file
  126.  * MAKE CHANGES TO THE DRIVER CONF FILE AND REBUILD RATHER THAN EDITING
  127.  * THIS FILE DIRECTLY.
  128.  */
  129.  
  130. #include <stdio.h>
  131. #include "defs.h"
  132. #include "smail.h"
  133. #include "addr.h"
  134. #include "direct.h"
  135. #include "route.h"
  136. #include "transport.h"
  137.  
  138. EOF
  139.  
  140.     while read a b; do
  141.         case "$a" in
  142.         %makefile_start)
  143.             outfile=$b/Makefile
  144.             if [ -f $outfile ]; then
  145.                 echo "Build $outfile, backup in .Makefile" 1>&2
  146.                 mv $outfile $b/.Makefile
  147.             else
  148.                 echo "Build $outfile ..." 1>&2
  149.             fi
  150.             cat <<EOF > $outfile
  151. # Makefile for the $b driver library in smail
  152.  
  153. # THIS FILE IS GENERATED AUTOMATICALLY BY THE SCRIPT $0 FROM
  154. # THE DRIVER CONFIGURATION FILE $driver_file
  155. # MAKE CHANGES TO THE DRIVER CONF FILE AND REBUILD RATHER THAN EDITING
  156.  
  157. SHELL=/bin/sh
  158. MAKE=make
  159. GET=sccs get
  160. AR=ar
  161. LINT=lint
  162. CC=cc
  163. CLEAN=sccs clean
  164. MK=\${MAKE} -\${MAKEFLAGS} SHELL=\${SHELL}
  165. SRC_PREFIX=
  166. ROOT=../..
  167. MKDEPEND=\${ROOT}/conf/lib/mkdepend.sh
  168. MKDEFS=\${ROOT}/conf/lib/mkdefs.sh
  169. CHECKDEFS=\${ROOT}/conf/lib/checkdefs.sh
  170. XEXEC=\${SHELL} \${ROOT}/conf/lib/xexec.sh
  171. DEFS_SH=defs.sh
  172. DEFS_H=defs.h
  173. DEFS_SED=defs.sed
  174.  
  175. EOF
  176.             ;;
  177.         %makefile_end)
  178.             cat <<\EOF >> $outfile
  179. SRC=${CSRC} ${HSRC}
  180.  
  181. .c.o:
  182.     @. ./${DEFS_SH}; ${XEXEC} $$CC $$CFLAGS $$INCLUDES -c $*.c
  183.  
  184. all:    ${TARGET}
  185.  
  186. lint:    ${CSRC} ${DEFS_SH}
  187.     @. ./${DEFS_SH}; ${XEXEC} ${LINT} ${LINTFLAGS} ${CSRC}
  188.  
  189. ${TARGET}: ${OBJ} Makefile ${DEFS_SH}
  190.     rm -f ${TARGET}
  191.     ${AR} cr ${TARGET} ${OBJ}
  192.     @. ./${DEFS_SH}; ${XEXEC} $$RANLIB ${TARGET}
  193.  
  194. csrc:;    @echo ${CSRC}
  195. hsrc:;    @echo ${HSRC}
  196.  
  197. sources: ${SRC}
  198.  
  199. ${SRC}:
  200.     ${GET} $@
  201.  
  202. ${DEFS_H} ${DEFS_SH} ${DEFS_SED}:
  203.     ROOT=${ROOT} ${SHELL} ${MKDEFS}
  204.  
  205. ${OBJ}:    ${DEFS_SH}
  206.  
  207. names:
  208.     @for i in ${SRC}; do echo ${SRC_PREFIX}$$i; done
  209.  
  210. depend:    ${SRC} check_defs
  211.     @. ./${DEFS_SH}; ${XEXEC} ${SHELL} ${MKDEPEND} $$CPPFLAGS $$INCLUDES \
  212.         Makefile ${CSRC}
  213.     . ./${DEFS_SH}; echo "$$DEFS_DEPEND" >> Makefile; \
  214.     chmod -w Makefile
  215.  
  216. check_defs:
  217.     SHELL=${SHELL} ROOT=${ROOT} ${SHELL} ${CHECKDEFS}
  218.  
  219. clean:
  220.     rm -f ${DEFS_SH} ${DEFS_H} ${DEFS_SED}
  221.     rm -f a.out core ${OBJ}
  222.     rm -f ${TARGET}
  223.  
  224. clobber: clean
  225.     rm -f .${DEFS_SH} .${DEFS_H} .${DEFS_SED} .Makefile
  226.     rm -f Makefile
  227.  
  228. nuke:   clobber
  229.     -${CLEAN}
  230.  
  231. # DO NOT REMOVE THIS LINE OR "make depend" WILL NOT WORK
  232. EOF
  233.             ;;
  234.         %drop)    echo "    $b" >> $outfile;;
  235.         *)    echo "$a $b" >> $outfile;;
  236.         esac
  237.     done
  238.     )
  239.